package hz.mobileproject.pda.firesafety.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.firesafety.bean.FireSafetyThingBean;

/**
 * Created by hasee on 2017/11/16.
 */

public class FireSafetyAdapter extends BaseAdapter {

    private List<FireSafetyThingBean> mList;

    private LayoutInflater mInflater;

    private Context mContext;

    public FireSafetyAdapter(Context context, List<FireSafetyThingBean> list){
        mContext = context;
        mList = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList == null ? null : mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if(view == null){
            view = mInflater.inflate(R.layout.fire_safety_list_item, null);
            vh = new ViewHolder();
            vh.tvBoxName = (TextView) view.findViewById(R.id.tv_fire_item_box_name);
            vh.tvAssetCode = (TextView) view.findViewById(R.id.tv_fire_item_asset_code);
            vh.tvCode = (TextView) view.findViewById(R.id.tv_fire_item_code);
            vh.tvName = (TextView) view.findViewById(R.id.tv_fire_item_name);
//            vh.tvNameId = (TextView) view.findViewById(R.id.tv_fire_item_name_id);
            vh.tvPurchaseDate = (TextView) view.findViewById(R.id.tv_fire_item_purchase_date);
            vh.tvProduceDate = (TextView) view.findViewById(R.id.tv_fire_item_produce_date);
            vh.tvExpiredDate = (TextView) view.findViewById(R.id.tv_fire_item_expired_date);
            vh.tvChangeDate = (TextView) view.findViewById(R.id.tv_fire_item_change_date);
            vh.tvImageUrl = (TextView) view.findViewById(R.id.tv_fire_item_image_url);
            vh.tvDeptId = (TextView) view.findViewById(R.id.tv_fire_item_dept_id);
            vh.tvDeptName = (TextView) view.findViewById(R.id.tv_fire_item_dept_name);
            view.setTag(vh);
        }else{
            vh = (ViewHolder) view.getTag();
        }

        vh.tvBoxName.setText(mList.get(i).getBoxName());
        vh.tvAssetCode.setText(mList.get(i).getAssetCode());
        vh.tvCode.setText(mList.get(i).getCode());
        vh.tvName.setText(mList.get(i).getName());
        vh.tvNameId.setText(mList.get(i).getNameId());
        vh.tvPurchaseDate.setText(mList.get(i).getPurchaseDate());
        vh.tvProduceDate.setText(mList.get(i).getProduceDate());
        vh.tvExpiredDate.setText(mList.get(i).getExpiredDate());
        vh.tvChangeDate.setText(mList.get(i).getChangeDate());
        vh.tvImageUrl.setText(mList.get(i).getImageUrl());
        vh.tvDeptId.setText(mList.get(i).getDeptId());
        vh.tvDeptName.setText(mList.get(i).getDeptName());
        return view;
    }

    static class ViewHolder{
        TextView tvBoxName;
        TextView tvAssetCode;
        TextView tvCode;
        TextView tvName;
        TextView tvNameId;
        TextView tvPurchaseDate;
        TextView tvProduceDate;
        TextView tvExpiredDate;
        TextView tvChangeDate;
        TextView tvImageUrl;
        TextView tvDeptId;
        TextView tvDeptName;
    }

}